 /*
  * Opacity and Fade in script.
  * Script copyright (C) 2008 http://www.cryer.co.uk/.
  * Script is free to use provided this copyright header is included.
  */
 function SetOpacity(object,opacityPct) {
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
 }

 function fademein(id) {
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.style.visibility = "visible";
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',500," + startMS + ",0,90)",1);
 }

 function fademeout(id) {
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',500," + startMS + ",90,0)",1);
 }

 function ChangeOpacity(id,msDuration,msStart,fromO,toO) {
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;

  /*
   * FOR FADING OUT:
   * The condition below tests whether the set opacity becomes
   * a negative number. If it is, then set the opacity to zero,
   * hide the overlay, and finish the script.
   */
  if (opacity<0) {
   SetOpacity(element,0)
   element.style.visibility="hidden";
  }

  /*
   * FOR FADING IN:
   * The condition below tests whether the set opacity becomes
   * greater than the desired opacity. If it is, then set the
   * opacity to the desired one and finish the script.
   */
  else if (opacity>90)
   SetOpacity(element,90)
  else {
   SetOpacity(element,opacity);
   element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
 }